<template>
  <div>
    <div class="clearfix">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#2a2d2f"
        text-color="#fff"
        active-text-color="#ffd04b"
        style="border-bottom: none;display: inline-block;float: left">
        <el-menu-item index="1" >全部任务</el-menu-item>
        <el-menu-item index="2" >我负责的任务</el-menu-item>
        <el-menu-item index="3" >已延期的任务</el-menu-item>
      </el-menu>
      <el-button type="primary" style="float: right;border-radius: 0 4px 4px 0;margin-top: 10px;margin-right: 15px;"
      @click="SearchProjectMission">搜索任务</el-button>
      <el-input
        placeholder="搜索任务编号寻找项目任务"
        v-model="Search"
        prefix-icon="el-icon-search"
        clearable
        class="searchMission">
      </el-input>
    </div>
    <div style="background-color: white; margin: 20px;padding:20px;height: 500px;" >
      <el-table
        :data="MissionTable"
        style="width: 100%;"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column
          prop="status"
          label="状态"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="name"
          label="标题"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="principal"
          label="负责人"
          show-overflow-tooltip>
          <template slot-scope="scope">
            <el-avatar style="float:left; margin-top:3px;" size="small" :src="scope.row.circleUrl" v-if="scope.row.principalName !== '无'"></el-avatar>
            <span style="float:left;margin-left: 5px;margin-top: 8px">{{ scope.row.principalName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="priority"
          label="优先级"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="startDate"
          label="开始时间"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="overDate"
          label="截止时间"
          show-overflow-tooltip>
        </el-table-column>
      </el-table>
      <div style="margin-top: 10px;text-align: center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 6, 7, 8]"
          :page-size="PageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  const axios = require('axios');
  export default {
    name: "taskManagement",
    data() {
      return {
        activeIndex : '1',

        //分页数据
        currentPage: 1,
        total: 0,
        PageSize: 5,
        currentTable: 1,

        Search: '',

        MissionTable:[],

      }
    },
    created() {
      this.$axios.all([
        axios.post('/getAllProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}),
        axios.post("/getProjectMessage",{"id":this.$route.params.id}),
      ]).then(this.$axios.spread((res1, res2) => {
        this.MissionTable = res1.data.list;
        this.total = res1.data.total;
        // console.log(res2);
        this.$parent.projectName = res2.data.projectName;
        this.$parent.topStatus = res2.data.topStatus;
        this.$parent.creatorId = res2.data.creatorId;
        this.$parent.principalId = res2.data.principalId;
      }))

    },
    methods: {
      handleSelect(key) {
        if(key == 1){
          axios.post('/getAllProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 1;
          })
        }else if(key == 2){
          axios.post('/getMyProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 2;
          })
        }else{
          axios.post('/getDelayProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 3;
          })
        }
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        if(this.currentTable = 1){
          axios.post('/getAllProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getMyProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else if(this.currentTable = 3){
          axios.post('/getDelayProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 3;
          })
        }else{
          axios.post('/getSearchProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 4;
          })
        }
      },
      handleSizeChange(val) {
        this.PageSize = val;
        if(this.currentTable = 1){
          axios.post('/getAllProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 1;
          })
        }else if(this.currentTable = 2){
          axios.post('/getMyProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"principal_id":window.localStorage.getItem("id")}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 2;
          })
        }else if(this.currentTable = 3){
          axios.post('/getDelayProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;;
            this.currentTable = 3;
          })
        }else{
          axios.post('/getSearchProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentTable = 4;
          })
        }
      },
      SearchProjectMission(){
        let reg = /^\d+$|^\d+[.]?\d+$/;
        if(this.Search == ""){
          this.$message.error("搜索不能为空")
        }else if(!reg.test(this.Search)) {
          this.$message.error("只能输入数字编号搜索")
        }else{
          axios.post('/getSearchProjectMission', {"pageCode":this.currentPage,"pageSize":this.PageSize,"id":this.$route.params.id,"missionId":this.Search}).then(res => {
            this.MissionTable = res.data.list;
            this.total = res.data.total;
            this.currentPage = 1;
            this.currentTable = 4;
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>
